const Sequelize = require('sequelize')
module.exports = function (sequelize, DataTypes) {
  return sequelize.define(
    'edu_videos',
    {
      id: {
        autoIncrement: true,
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true,
        comment: '视频ID'
      },
      course_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '课程ID'
      },
      chapter_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '章节ID',
        references: {
          model: 'edu_chapters',
          key: 'id'
        }
      },
      lessonName: {
        type: DataTypes.STRING(50),
        allowNull: false,
        comment: '课时名称'
      },
      description: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '课时描述'
      },
      video_source_id: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '云端视频资源'
      },
      video_original_name: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '原始文件名称'
      },
      sort: {
        type: DataTypes.INTEGER.UNSIGNED,
        allowNull: false,
        defaultValue: 0,
        comment: '排序字段'
      },
      play_count: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
        defaultValue: 0,
        comment: '播放次数'
      },
      is_free: {
        type: DataTypes.TINYINT.UNSIGNED,
        allowNull: false,
        defaultValue: 0,
        comment: '是否可以试听：0收费 1免费'
      },
      duration: {
        type: DataTypes.FLOAT,
        allowNull: false,
        defaultValue: 0,
        comment: '视频时长（秒）'
      },
      status: {
        type: DataTypes.STRING(20),
        allowNull: false,
        defaultValue: 'Empty',
        comment: 'Empty未上传 Transcoding转码中  Normal正常'
      },
      size: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
        defaultValue: 0,
        comment: '视频源文件大小（字节）'
      },
      version: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
        defaultValue: 1,
        comment: '乐观锁'
      }
    },
    {
      sequelize,
      tableName: 'edu_videos',
      timestamps: false,
      indexes: [
        {
          name: 'PRIMARY',
          unique: true,
          using: 'BTREE',
          fields: [{ name: 'id' }]
        },
        {
          name: 'chapter_id',
          using: 'BTREE',
          fields: [{ name: 'chapter_id' }]
        }
      ]
    }
  )
}
